package org.openkanban.client.ui.board;

import com.smartgwt.client.util.Page;
import com.smartgwt.client.widgets.events.DoubleClickEvent;
import com.smartgwt.client.widgets.events.DoubleClickHandler;
import com.smartgwt.client.widgets.tile.TileGrid;
import com.smartgwt.client.widgets.tile.TileRecord;
import com.smartgwt.client.widgets.viewer.DetailViewerField;

/**
 * GUI Element for the KanbanContactTileGrid
 */
public class KanbanContactTileGrid extends TileGrid {

    public KanbanContactTileGrid() {
	setWidth100();
	setHeight100();
	setTileWidth(30);
	setTileHeight(35);
	setCanAcceptDrop(true);
	setCanAcceptDroppedRecords(true);
	setCanDrag(false);
	setPreventDuplicates(true);
	setAutoFetchData(false);
	setSmoothFade(true);
	setStyleName("kanbanContactTileGrid");
	setMargin(0);
	setPadding(0);
	setTileVMargin(1);
	setTileHMargin(3);

	setData(new TileRecord[] {});

	DetailViewerField namensKuerzel = new DetailViewerField("namensKuerzel", "Vorname");

	DetailViewerField avatar = new DetailViewerField("avatarUrl", " ");
	avatar.setType("image");
	avatar.setImageURLPrefix(Page.getAppImgDir() + "avatar/");
	avatar.setImageHeight(20);
	avatar.setImageWidth(20);

	setFields(avatar, namensKuerzel);

	addDoubleClickHandler(new DoubleClickHandler() {

	    @Override
	    public void onDoubleClick(DoubleClickEvent event) {
		KanbanContactTileGrid bctg = (KanbanContactTileGrid) event.getSource();
		TileRecord tr = bctg.getSelectedRecord();
		if (tr != null) {
		    bctg.removeSelectedData();
		}
	    }
	});

    }

}
